﻿using System;
namespace KL.UFrame.Core.Log
{
    public class CommonLogger:ICommonLogger
    {
        private NLog.ILogger _logger;
        
        public CommonLogger(NLog.Logger logger)
        {
            this._logger = logger;
        }

        public void Error(string message, System.Exception ex = null)
        {
            if (ex != null)
            {
                var exceptionMessage = ex.Message;
                
                var innerException = ex.InnerException;
                while (innerException != null)
                {
                    exceptionMessage += Environment.NewLine + innerException.Message;
                    innerException = innerException.InnerException;
                }

                message += Environment.NewLine + exceptionMessage;

                _logger.Error(message + Environment.NewLine + ex.StackTrace);
            }
            else
            {
                _logger.Error(message);
            }
        }

        public void Info(string message)
        {
            _logger.Info(message);
        }

        public void Debug(string message)
        {
           _logger.Debug(message);
        }
    }
}